package com.goddess.yeecolor.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.goddess.yeecolor.Modle.SecondBean;
import com.goddess.yeecolor.R;
import com.goddess.yeecolor.tools.ImageUtils;

import java.util.ArrayList;

/**
 * 二级菜单适配器
 * Created by Administrator on 2016/7/18.
 */
public class ExpandableListViewAdapterTo extends BaseExpandableListAdapter {
    private Context mContext;
    private ArrayList<SecondBean> mDatas;
    int mPosition;
    public ExpandableListViewAdapterTo(Context context, ArrayList<SecondBean> data, int pos){
        this.mContext = context;
        this.mDatas = data;
        this.mPosition = pos;
    }
    @Override
    public int getGroupCount() {
        return mDatas!= null?mDatas.size():0;
    }

    @Override
    public int getChildrenCount(int childPosition) {
        return 0;
    }

    @Override
    public Object getGroup(int parentPosition) {
        return mDatas.get(parentPosition);
    }

    @Override
    public Object getChild(int parentPosition, int childPosition) {
        return null;
    }

    @Override
    public long getGroupId(int parentPosition) {
        return parentPosition;
    }

    @Override
    public long getChildId(int parentPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    /**
     * 主菜单布局
     * @param parentPosition
     * @param isExpandabled
     * @param view
     * @param viewGroup
     * @return
     */
    @Override
    public View getGroupView(int parentPosition, boolean isExpandabled, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if(view == null){
            view = LayoutInflater.from(mContext).inflate(R.layout.expandable_listview_to_item,null);
            holder = new ViewHolder();
            holder.title = (TextView)view.findViewById(R.id.title);
            holder.img = (ImageView) view.findViewById(R.id.img);
            holder.date = (TextView)view.findViewById(R.id.date);
            view.setTag(holder);
        }else{
            holder = (ViewHolder) view.getTag();
        }
        ImageUtils.getInstance().ImageStart(mContext,mDatas.get(parentPosition).getImg(),holder.img);
        holder.img.setScaleType(ImageView.ScaleType.FIT_XY);
        holder.title.setText(mDatas.get(parentPosition).getTitle());
        holder.date.setText(mDatas.get(parentPosition).getDate());
        holder.webview=mDatas.get(parentPosition).getWebview();
        holder.id=mDatas.get(parentPosition).getId();
        holder.price=mDatas.get(parentPosition).getPrice();

        return view;
    }




    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        return null;
    }

    class ViewHolder {
        private ImageView img;
        private TextView title;
        private TextView date;
        private String webview;
        private String id;
        private String price;
    }
    @Override
    public boolean isChildSelectable(int i, int i1) {
        return true;
    }


}
